package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.manage.domain.db.User;
import com.tanhua.manage.domain.db.UserInfo;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;

    /**
     * 添加用户
     * @param user
     * @return
     */
    @Override
    public Long save(User user) {

        //给user更新创建时间和更新时间
        //由mybatis plus自动填充
        //user.setCreated(new Date());
        //user.setUpdated(new Date());
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 通过手机号码查询
     * @param mobile
     * @return
     */
    @Override
    public User findByMobile(String mobile) {
        //设置查询条件
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile",mobile);
        //调用mapper查询
        return userMapper.selectOne(queryWrapper);
    }

    /**
    更新用户信息
     */
    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }
    /**
     更新用户头像
     */

}
